﻿using System.Threading;
using System.Windows;

namespace MaxStoreErp.Shell
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App
    {
        const string APP_GUID = "{C16E6616-9601-4099-8A6A-6B6F9C98C8B9}";
        static Mutex _mutex;

        protected override void OnStartup(StartupEventArgs e)
        {
            if (!IsOnlyInstance())
            {
                MessageBox.Show("MaxStoreErp уже запущено!", "Внимание", MessageBoxButton.OK,
                MessageBoxImage.Exclamation);
                Current.Shutdown();
            }
            base.OnStartup(e);
            var bootstrapper = new Bootstrapper();
            bootstrapper.Run();
        }

        bool IsOnlyInstance()
        {
            bool onlyInstance;
            const string mutexName = APP_GUID;
            _mutex = new Mutex(true, mutexName, out onlyInstance);
            return onlyInstance;
        }
    }
}
